package com.example.foreach;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.RandomUtil;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @description:
 * @author: csp
 * @date: 2020-12-03 11:30
 */
public class ForeachTest {
    public static List<String> list = new ArrayList<>();

    static {
        for (int i = 0; i < 100000; i++) {
            list.add(UUID.randomUUID().toString());
        }
    }

    @Test
    public void test() {
        System.out.println(list);
    }

    @Test
    public void test1() {
        list.forEach(str -> {
//            try {
//                Thread.sleep(1);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            System.out.println(Thread.currentThread().getName() + ":" + str);
        });
    }

    @Test
    public void test2() {
        list.stream().forEach(str -> {
//            try {
//                Thread.sleep(1);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            System.out.println(Thread.currentThread().getName() + ":" + str);
        });
    }

    @Test
    public void test3() {
        list.parallelStream().forEach(str -> {
//            try {
//                Thread.sleep(1);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            System.out.println(Thread.currentThread().getName() + ":" + str);
        });
    }

    @Test
    public void test4() {
        for (int i = 0; i < list.size(); i++) {
//            try {
//                Thread.sleep(1);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            System.out.println(Thread.currentThread().getName() + ":" + list.get(i));
        }
    }

    @Test
    public void test5() {
        for (String str : list) {
//            try {
//                Thread.sleep(1);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            System.out.println(Thread.currentThread().getName() + ":" + str);
        }
    }


    @Test
    public void test6() {
//        Supplier<List> s1 = () -> List.of(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString());
//
//        Supplier<List[]> s2 = () -> {
//            List[] lists = new List[];
//            for (int i = 0; i < 5; i++) {
//                lists[i] = s1.get();
//            }
//            return lists;
//        }
//        List<List> lists1 = new ArrayList<>();
//        for (int i = 0; i < 5; i++) {
//            lists1
//        }
    }
    @Test
    public void test7(){

    }

    @Test
    public void test8(){
        for (int i = 0; i < 0; i++) {

        }

    }

}

